package demoMod.plugins.mod.sts.ui;

import javax.swing.*;
import java.lang.reflect.Field;
import java.util.Locale;

public class ProjectConfigUI {

    private JPanel mainPanel;
    private JTextField modIdField;
    private JTextField modNameField;
    private JTextField descriptionField;
    private JTextField packageField;
    private JTextField versionField;
    private JTextField steamPathField;
    private JButton chooseSteamPathButton;
    private JList<String> dependencyList;
    private JList<String> subscribersList;
    private JCheckBox chkAddMonsters;
    private JCheckBox chkAddEvents;
    private JCheckBox chkAddPotions;
    private JCheckBox chkEng;
    private JCheckBox chkDut;
    private JCheckBox chkEpo;
    private JCheckBox chkPtb;
    private JCheckBox chkZhs;
    private JCheckBox chkZht;
    private JCheckBox chkFra;
    private JCheckBox chkDeu;
    private JCheckBox chkGre;
    private JCheckBox chkInd;
    private JCheckBox chkIta;
    private JCheckBox chkJpn;
    private JCheckBox chkKor;
    private JCheckBox chkNor;
    private JCheckBox chkPol;
    private JCheckBox chkRus;
    private JCheckBox chkSpa;
    private JCheckBox chkSrp;
    private JCheckBox chkSrb;
    private JCheckBox chkTha;
    private JCheckBox chkTur;
    private JCheckBox chkUkr;
    private JCheckBox chkVie;

    public ProjectConfigUI() {
        chooseSteamPathButton.addActionListener(e -> {

        });
        dependencyList.addListSelectionListener(e -> {
            int[] indexes = dependencyList.getSelectedIndices();
            ListModel<String> model = dependencyList.getModel();
            boolean canChooseSubscribers = false;
            for (int index : indexes) {
                if ("basemod".equals(model.getElementAt(index))) {
                    canChooseSubscribers = true;
                    break;
                }
            }
            subscribersList.setEnabled(canChooseSubscribers);
        });
        subscribersList.addListSelectionListener(e -> {
            int[] indexes = subscribersList.getSelectedIndices();
            ListModel<String> model = subscribersList.getModel();
            boolean canChooseCheckboxes = false;
            for (int index : indexes) {
                if ("PostInitializeSubscriber".equals(model.getElementAt(index))) {
                    canChooseCheckboxes = true;
                    break;
                }
            }
            chkAddMonsters.setEnabled(canChooseCheckboxes);
            chkAddEvents.setEnabled(canChooseCheckboxes);
            chkAddPotions.setEnabled(canChooseCheckboxes);

            canChooseCheckboxes = false;
            for (int index : indexes) {
                if ("EditStringsSubscriber".equals(model.getElementAt(index))) {
                    canChooseCheckboxes = true;
                    break;
                }
            }
            for (Field field : ProjectConfigUI.class.getDeclaredFields()) {
                if (field.getName().startsWith("chk") && !field.getName().startsWith("chkAdd")) {
                    field.setAccessible(true);
                    try {
                        JCheckBox checkBox = (JCheckBox) field.get(this);
                        checkBox.setEnabled(canChooseCheckboxes);
                    } catch (IllegalAccessException ex) {
                        ex.printStackTrace();
                    }
                }
            }
        });
    }

    public JComponent getComponent(){
        return mainPanel;
    }

    public JTextField getModIdField() {
        return modIdField;
    }

    public JTextField getModNameField() {
        return modNameField;
    }

    public JTextField getDescriptionField() {
        return descriptionField;
    }

    public JTextField getPackageField() {
        return packageField;
    }

    public JTextField getVersionField() {
        return versionField;
    }

    public JTextField getSteamPathField() {
        return steamPathField;
    }

    public JButton getChooseSteamPathButton() {
        return chooseSteamPathButton;
    }

    public JList<String> getDependencyList() {
        return dependencyList;
    }

    public JList<String> getSubscribersList() {
        return subscribersList;
    }

    public JCheckBox getChkAddMonsters() {
        return chkAddMonsters;
    }

    public JCheckBox getChkAddEvents() {
        return chkAddEvents;
    }

    public JCheckBox getChkAddPotions() {
        return chkAddPotions;
    }
}
